/**
 * 
 */
package com.thor.palmmall.rest.servicebill.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.servicebill.AServiceBillQueryParam;
import com.thor.palmmall.spi.servicebill.SServiceBillQueryParam;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SServiceBillQueryParamConverter
    implements Converter<AServiceBillQueryParam, SServiceBillQueryParam> {

  public static SServiceBillQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SServiceBillQueryParamConverter();
    return instance;
  }

  private static SServiceBillQueryParamConverter instance;

  private SServiceBillQueryParamConverter() {
  }

  @Override
  public SServiceBillQueryParam convert(AServiceBillQueryParam source) {
    if (source == null)
      return null;

    SServiceBillQueryParam target = new SServiceBillQueryParam();
    target.setContracts(new ArrayList<UCN>());
    if (source.getContracts() != null)
      for (UCN sourceContract : source.getContracts())
        target.getContracts().add(UCN.newInstance(sourceContract));
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(source.getStores());
    target.setUserGroups(new ArrayList<KV>());
    for (KV sourceUserGroup : source.getUserGroups())
      target.getUserGroups().add(KV.newInstance(sourceUserGroup));
    target.setOrder(source.getOrder());

    target.setKeyword(source.getKeyword());
    target.setBeginTime(source.getBeginTime());
    target.setEndTime(source.getEndTime());
    target.setState(source.getState());
    target.setParams(source.getParams());

    return target;
  }

}
